<?php
require_once dirname(__FILE__).'/smonitor.php';
require_once dirname(__FILE__).'/pssmonitor.php';
$sm=new smonitor();
$pm=new pssmonitor();
$xmlfile="/soooner/pss/svc.xml";
$fp = fopen($xmlfile, 'r');
$xmldata = fread($fp, filesize($xmlfile));
fclose($fp);
$doc = new DOMDocument();
$doc->loadXML($xmldata);
$items = $doc->getElementsByTagName("service");
$resulthtml="<html><head>\n";
$resulthtml.="<meta http-equiv=content-type content='text/html; charset=utf-8' />\n";
$resulthtml.="<meta http-equiv=refresh content='30'>\n";
$resulthtml.="<style type='text/css'><!--\n";
$resulthtml.="div{margin:2px 5px}\n";
$resulthtml.=".c00{color:green;border:1px green solid;float:left}\n";
$resulthtml.=".c10{color:red;border:1px red solid;float:left}\n";
$resulthtml.=".c11{color:red;border:1px red solid;float:left}\n";
$resulthtml.=".c01{color:blue;border:1px blue solid;float:left}\n";
$resulthtml.=".ct{color:#ffffff;padding:10px;background-color:#666666;clear:both}\n";
$resulthtml.="--></style></head><body>";
$resulthtml.="<div class='ct'>监控时间：".date('Y-m-d H:i:s',time())."</div>";
$error=0;
foreach($items as $item){
	$id = $item->getAttribute("id");
	$url = $item->getElementsByTagName("url")->item(0)->nodeValue;
	$tspath = $item->getElementsByTagName("tspath")->item(0)->nodeValue;
	$r = $sm->check($url,$id);
	$r1 = $pm->check($tspath);
	$error+=$r+$r1;
	if($r+$r1==0)
            $resulthtml.="<div class='c$r$r1'>$id:OK</div>\n";
    else
            $resulthtml.="<div class='c$r$r1'>$id:$url</div>\n";
}
if($error>0){
	$resulthtml.="<bgsound src='beatles.mid' />";
}
$resulthtml.="</body></html>";
file_put_contents("/data/web/public/monitor.html",$resulthtml);
